/*
 * Copyright (C) 2016 The Fosafer Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.fosafer.idcard_demo.util;

import android.widget.Toast;

import com.fosafer.idcard_demo.app.IDCardApp;

/**
 * Package:      [com.fosafer.idcard_demo.util]
 * ClassName:    [ToastUtil]
 * Description:  [Toast工具类,]
 * Author:       [cuijianzhi]
 * CreateDate:   [2016/04/19 15:22]
 * UpdateUser:   [cuijianzhi]
 * UpdateDate:   [2016/04/19 15:22]
 * UpdateRemark: [Update Description]
 * Version:      [v1.0.0]
 * <p/>
 * Copyright (c) 2016 Fosafer Co.,Ltd. All rights reserved.
 */
public class ToastUtil {
    private static Toast mToast;

    /**
     * 短时间显示Toast.
     *
     * @param resId resId
     */
    public static void showShort(final int resId) {
        // 解决Toast连点显示不及时的问题
        if (mToast == null) {
            mToast = Toast.makeText(IDCardApp.getInstance(), resId, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(resId);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    /**
     * 短时间显示Toast.
     *
     * @param msg msg
     */
    public static void showShort(final String msg) {
        // 解决Toast连点显示不及时的问题
        if (mToast == null) {
            mToast = Toast.makeText(IDCardApp.getInstance(), msg, Toast.LENGTH_SHORT);
        } else {
            mToast.setText(msg);
            mToast.setDuration(Toast.LENGTH_SHORT);
        }
        mToast.show();
    }

    /**
     * 短时间显示Toast.
     *
     * @param resId resId
     */
    public static void showLong(final int resId) {
        // 解决Toast连点显示不及时的问题
        if (mToast == null) {
            mToast = Toast.makeText(IDCardApp.getInstance(), resId, Toast.LENGTH_LONG);
        } else {
            mToast.setText(resId);
            mToast.setDuration(Toast.LENGTH_LONG);
        }
        mToast.show();
    }

    /**
     * 短时间显示Toast.
     *
     * @param msg msg
     */
    public static void showLong(final String msg) {
        // 解决Toast连点显示不及时的问题
        if (mToast == null) {
            mToast = Toast.makeText(IDCardApp.getInstance(), msg, Toast.LENGTH_LONG);
        } else {
            mToast.setText(msg);
            mToast.setDuration(Toast.LENGTH_LONG);
        }
        mToast.show();
    }


}
